<template>

  <div class="layui-layout layui-layout-admin">
    <div class="adminnav1">
      <Pagetop></Pagetop>
    </div>
    <div class="adminnav2">
      <Secondnav urlname="retail"></Secondnav>
    </div>

    <!-- 主体内容 -->
    <div class="layui-body kedou-admin" id="LAY_app_body app">
      <div class="layadmin-tabsbody-item layui-show">
        <div class="pagelist">
          <div class="layui-card-body">
            <fieldset class="layui-elem-field layui-field-title">
              <legend>推广订单管理</legend>
            </fieldset>
          </div>
          <div class="pagetop">
            <Search :seadate="searchArr"></Search>
          </div>
          <div class="layui-card-body">
            <div class="buttop" id="buttop">
              <button type="button" class="layui-btn" @click="getData(0)">全部</button>
              <button type="button" class="layui-btn  layui-btn-primary" @click="getData(1)">待结算</button>
              <button type="button" class="layui-btn  layui-btn-primary" @click="getData(2)">已完成</button>
              <button type="button" class="layui-btn  layui-btn-primary" @click="getData(3)">已失效</button>
              <!--  <button type="button" class="layui-btn  layui-btn-normal"  @click="daochu">导出</button>-->
            </div>
            <Tables :fdate="pdate" :result="res" height="430" :totalCount="totalRows" :pageNumber="curindex"
              :fbtn="btn"></Tables>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>
<script>	
import Pagetop from '../common/pagetop.vue'
import Secondnav from '../common/secondnav.vue'
import Tables from '../common/tables.vue'
import Search from '../common/search.vue'
export default {
  name: 'promoterorder',
  components: { Pagetop, Secondnav, Tables, Search },
  data () {
    return {
      pdate: [], //表头  	
      res: "", //内容
      totalRows: "",//总数量
      curindex: 1, //页数
      btn: [],//按钮
      searchArr: [],//搜索
      isShow: false,
      seapram: '',
      isclick: 0,
      settlementStatus: '',// 待结算WAITSETTLE，已完成HASBEENSETTLED，退款REFUND
    }
  },
  mounted () {
    this.getdate();
    this.getsearch();
  },
  methods: {
    getdate: function () {
      var _this = this;
      if (_this.isclick == 0) {
        var status = '';
      } else if (_this.isclick == 1) {
        var status = 'WAITSETTLE';
      } else if (_this.isclick == 2) {
        var status = 'HASBEENSETTLED';
      } else if (_this.isclick == 3) {
        var status = 'REFUND';
      }
      var url = "/retail/bapi/v1.9/share-orders/shareOrdersPage"
      if (_this.seapram) {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          'settlementStatus.equals': status,
          sort:'createAt,desc',
          //'status.equals':'ENABLE'
        }
        var res = _this.seapram;
        for (var i = 0; i < res.length; i++) {
          //dates[res[i].key]=res[i].val;
          dates[res[i].key + '.contains'] = res[i].val;
        }

      } else {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          'settlementStatus.equals': status,
          sort:'createAt,desc',
          //'status.equals':'ENABLE'
        }
      }
      //	alert(url+"//"+JSON.stringify(dates))
      ajaxRequest(url, 'GET', 'json', dates, function (ret, err) {
        //alert(url+"//"+JSON.stringify(ret))
        var arr = [];
        arr[0] = [
          { field: 'id', title: 'ID', width: '7%' }
          //		      ,{field: 'createAt', title: '创建日期',templet:function(d){return FormatDate(d.createAt,2)}}
          , { field: 'accountName', title: '用户账号', width: '7%' }
          , {            field: 'tradeTypeId', title: '交易分类', width: '5%', templet: function (d) {
              if (d.tradeTypeId == 1001) return '商品消费'
              else return '活动'
            }          }
          , {            field: 'sharer', title: '上级', width: '5%', templet: function (d) {
              if (d.sharer.referrer) {
                return d.sharer.referrer
              } else { return '暂无' }
            }          }
          , { field: 'sharer', title: '分享商', width: '5%', templet: function (d) { return d.sharer.nickName } }
          , { field: 'sharer', title: '团队归属名', width: '8%', templet: function (d) { return d.sharer.teamUserName } }
          , { field: 'amount', title: '金额（元）', width: '6%', templet: function (d) { return d.amount / 100 } }
          , { field: 'rebateAmount', title: '合计奖金（元）', width: '7%', templet: function (d) { return d.rebateAmount / 100 } }
          , { field: 'subLedgerNum', title: '分账人数', width: '5%', }
          , {            field: 'shareOrderUsersList', title: '分账用户', width: '6%', templet: function (d) {
              if (d.shareOrderUsersList != null) {
                for (var i = 0; i < d.shareOrderUsersList.length; i++) {
                  return d.shareOrderUsersList[i].accountName
                }
              }
            }          }
          , {            field: 'shareOrderUsersList', title: '分账金额（元）', width: '7%', templet: function (d) {
              if (d.shareOrderUsersList != null) {
                for (var i = 0; i < d.shareOrderUsersList.length; i++) {
                  return d.shareOrderUsersList[i].subLedgerAmount / 100
                }
              }
            }          }
          , {            field: 'settlementStatus', title: '结算状态', width: '5%', templet: function (d) {
              if (d.settlementStatus == 'WAITSETTLE') return '待结算'
              else if (d.settlementStatus == 'HASBEENSETTLED') return '已完成'
              else if (d.settlementStatus == 'REFUND') return '已退款'
              else return ''
            }          }
          , { field: 'settlementAt', title: '结算时间', width: '10%', templet: function (d) { return FormatDate(d.settlementAt, 3) } }
          , { field: 'createAt', title: '创建时间', width: '10%', templet: function (d) { return FormatDate(d.createAt, 3) } }
          ,
          {
            field: "right",
            title: "操作",
            width: "7%",
            fixed: "right",
            templet: function (d) {
              var str =
                '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">查看分账用户</a>';
              return str;
            }
          }
        ];
        //		    var res1=[]
        //		    res1=[{a:'1',b:'小m'},{a:'1',b:'小m'},]		    		   		  	
        _this.pdate = arr;
        _this.res = ret.data.list; //res1; 		  
        _this.totalRows = ret.data.totalRows;
        _this.curindex = ret.data.page + 1;
      })
    },
    getsearch: function () {
      var arr = [
        { field: 'id', title: '订单号', type: 'input' }
      ];
      this.searchArr = arr;

    },
    page: function (index, obj) {
      //alert(JSON,stringify(obj))
      this.curindex = index;
      this.getdate();

    },
    sousuo: function (pram) {
      //alert(JSON.stringify(pram))
      this.seapram = pram;
      this.res = '';
      this.totalRows = '';
      this.curindex = 1;
      this.getdate();
    },
    daochu: function () {
      alert('开发中')
    },
    getData: function (is) {
      this.isclick = is;
      this.getdate();
      if (is == 0) {
        $('#buttop').find('.layui-btn:eq(0)').removeClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(1)').addClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(2)').addClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(3)').addClass('layui-btn-primary')
      } else if (is == 1) {
        $('#buttop').find('.layui-btn:eq(1)').removeClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(0)').addClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(2)').addClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(3)').addClass('layui-btn-primary')
      } else if (is == 2) {
        $('#buttop').find('.layui-btn:eq(2)').removeClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(0)').addClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(1)').addClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(3)').addClass('layui-btn-primary')
      } else if (is == 3) {
        $('#buttop').find('.layui-btn:eq(3)').removeClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(0)').addClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(1)').addClass('layui-btn-primary')
        $('#buttop').find('.layui-btn:eq(2)').addClass('layui-btn-primary')
      }

    },
    addData: function () {
      // this.$router.push({name:'jfadd'})	
    },
    editInfo: function (data) {
      //this.$router.push({name:'jfadd',query:{'shopId':data.shopId,'commodityId':data.commodityId}})	
    },
    detailInfo: function (data) {
      var _this = this;
      var id = data.id;
      this.$router.push({
        path: "/promoterorderdetail",
        query: {
          id: id
        }
      });

    },

    screens: function () {
      return screen();
    },
  },
  updated: function () {
    this.isShow = true;
    layui.use('form', function () {
      var form = layui.form;
      form.render();
    });
  },
}
</script>
<style scoped>
/**/
</style>
